class Solution {
    public List<List<Integer>> findMatrix(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        int n = nums.length;
        boolean[] visited = new boolean[n];
        Arrays.sort(nums);
        int count = 0;
        while (true) {
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                if (visited[i])
                    continue;
                if (set.contains(nums[i]))
                    continue;
                set.add(nums[i]);
                visited[i] = true;
            }
            count += set.size();
            ans.add(new ArrayList<>(set));
            if (count == n)
                break;
        }
        return ans;
    }
}